package nl.sportan.samenloop.adapter;

import nl.sportan.samenloop.R;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ViewPagerAdapter extends PagerAdapter {
	private static int[] content_ids = new int[] { 
		R.string.history,
		R.string.ceremony, 
		R.string.candles,
		R.string.closing
			};

	private static int[] image_ids = new int[] { 
		R.drawable.relay,
		R.drawable.opening,
		R.drawable.candles,
		R.drawable.closing,
	};

	private final Context context;

	public ViewPagerAdapter(Context context) {
		this.context = context;
	}

	private View createHistoryView(View pager, int id, int image) {
		View v = (LinearLayout) LayoutInflater.from(context).inflate(
				R.layout.samenloop_info_view, ((ViewPager) pager), false);

		TextView wv = (TextView) v.findViewById(R.id.content);
		String data = context.getString(id);

		ImageView iv = (ImageView) v.findViewById(R.id.image);
		iv.setImageBitmap(BitmapFactory.decodeResource(context.getResources(), image));
		
		wv.setText(Html.fromHtml(data + "<br/><br/>"));

		return v;
	}

	@Override
	public int getCount() {
		return content_ids.length;
	}

	@Override
	public Object instantiateItem(View pager, int position) {
		View v = createHistoryView(pager, content_ids[position], image_ids[position]);
		((ViewPager) pager).addView(v, 0);

		return v;
	}

	@Override
	public void destroyItem(View pager, int position, Object view) {
		((ViewPager) pager).removeView((LinearLayout) view);
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view.equals(object);
	}

	@Override
	public void finishUpdate(View view) {
	}

	@Override
	public void restoreState(Parcelable p, ClassLoader c) {
	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View view) {
	}
}